import useReq from "@/hooks/useReq.tsx";
import {LoginParams, LoginResp} from "@/types/types.ts";

export default function useApi() {
  const {request} = useReq();

  async function login(data: LoginParams) {
    return await request<LoginParams, LoginResp>('/api/v1/auth/login', { method: 'POST', data})
  }

  async function logout() {
    await request('/api/v1/auth/logout', { method: 'POST'})
  }

  const fetchUserInfo = async () => {
    const resp = await request<void, {name: string}>('/api/v1/users/currentUser', {method: 'GET'})
    return resp.data
  }

  return {login, logout, fetchUserInfo}
}



